const { exec } = require('child_process');
const { resolve } = require('path')
// 返回运行文件所在的目录
console.log('__dirname : ' + __dirname)
// __dirname : /Desktop

// 当前命令所在的目录
console.log('resolve   : ' + resolve('./'))
// resolve   : /workspace

// 当前命令所在的目录
console.log('cwd       : ' + process.cwd())
// cwd       : /workspace

// 当前文件的上级目录
console.log('../       : ' + resolve(__dirname, 'output/*'))//
const basePath = resolve(__dirname, 'output')
const cmdRun = (order)=>{
    return new Promise((resolve, rejects)=>{
        if(order) {
            exec(order, (error, stdout, stderr) => {
              if (error) {
                rejects(`执行的错误: ${error}`);
                return;
              }
              if (stderr) {
                rejects(`标准错误输出: ${stderr}`);
                return
              }
              resolve(`标准输出:\n${stdout}`);
            });
        }else{
            rejects()
        }
    })
}
cmdRun(`IF EXIST  "${basePath}" rmdir /Q /s "${basePath}"`).then(res=>{
    cmdRun(`md "${basePath}"`).then(res=>{

    })
})